package cn.creditharmony.loan.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class DateTest {

	public XMLGregorianCalendar convertToXMLGregorianCalendar(Date date) {

		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(date);
		XMLGregorianCalendar gc = null;
		try {
			gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
		} catch (Exception e) {

			e.printStackTrace();
		}
		return gc;
	}

	public Date convertToDate(XMLGregorianCalendar cal) throws Exception {
		GregorianCalendar ca = cal.toGregorianCalendar();
		return ca.getTime();
	}

	public static void main(String[] args) {
		DateTest dateTest = new DateTest();
		XMLGregorianCalendar d = dateTest.convertToXMLGregorianCalendar(new Date());
		System.out.println(d.getDay());
		XMLGregorianCalendar cal = null;
		try {
			cal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
			cal.setMonth(06);
			cal.setYear(2010);
			Date date = dateTest.convertToDate(cal);

			XMLGregorianCalendar a = dateTest.convertToXMLGregorianCalendar(date);
			System.out.println(a);
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
